<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>eager_global_ordinals | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'eager-global-ordinals.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/eager-global-ordinals.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/eager-global-ordinals.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/eager-global-ordinals.html" rel="nofollow" target="_blank">../en/eager-global-ordinals.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="mapping.html">Mapping</a></span>
»
<span class="breadcrumb-link"><a href="mapping-params.html">Mapping parameters</a></span>
»
<span class="breadcrumb-node"><code class="literal">eager_global_ordinals</code></span>
</div>
<div class="navheader">
<span class="prev">
<a href="dynamic.html">« <code class="literal">dynamic</code></a>
</span>
<span class="next">
<a href="enabled.html"><code class="literal">enabled</code> »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="eager-global-ordinals"></a><code class="literal">eager_global_ordinals</code><a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/mapping/params/eager-global-ordinals.asciidoc">edit</a>
</h2>
</div></div></div>
<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="_what_are_global_ordinals"></a>What are global ordinals?<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/mapping/params/eager-global-ordinals.asciidoc">edit</a>
</h3>
</div></div></div>
<p>To support aggregations and other operations that require looking up field
values on a per-document basis, Elasticsearch uses a data structure called
<a class="xref" href="doc-values.html" title="doc_values">doc values</a>. Term-based field types such as <code class="literal">keyword</code> store
their doc values using an ordinal mapping for a more compact representation.
This mapping works by assigning each term an incremental integer or <em>ordinal</em>
based on its lexicographic order. The field’s doc values store only the
ordinals for each document instead of the original terms, with a separate
lookup structure to convert between ordinals and terms.</p>
<p>When used during aggregations, ordinals can greatly improve performance. As an
example, the <code class="literal">terms</code> aggregation relies only on ordinals to collect documents
into buckets at the shard-level, then converts the ordinals back to their
original term values when combining results across shards.</p>
<p>Each index segment defines its own ordinal mapping, but aggregations collect
data across an entire shard. So to be able to use ordinals for shard-level
operations like aggregations, Elasticsearch creates a unified mapping called
<em>global ordinals</em>. The global ordinal mapping is built on top of segment
ordinals, and works by maintaining a map from global ordinal to the local
ordinal for each segment.</p>
<p>Global ordinals are used if a search contains any of the following components:</p>
<div class="ulist itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
Certain bucket aggregations on <code class="literal">keyword</code>, <code class="literal">ip</code>, and <code class="literal">flattened</code> fields. This
includes <code class="literal">terms</code> aggregations as mentioned above, as well as <code class="literal">composite</code>,
<code class="literal">diversified_sampler</code>, and <code class="literal">significant_terms</code>.
</li>
<li class="listitem">
Bucket aggregations on <code class="literal">text</code> fields that require <a class="xref" href="fielddata.html" title="fielddata"><code class="literal">fielddata</code></a>
to be enabled.
</li>
<li class="listitem">
Operations on parent and child documents from a <code class="literal">join</code> field, including
<code class="literal">has_child</code> queries and <code class="literal">parent</code> aggregations.
</li>
</ul>
</div>
<div class="note admon">
<div class="icon"></div>
<div class="admon_content">
<p>The global ordinal mapping is an on-heap data structure. When measuring
memory usage, Elasticsearch counts the memory from global ordinals as
<em>fielddata</em>. Global ordinals memory is included in the
<a class="xref" href="circuit-breaker.html#fielddata-circuit-breaker" title="Field data circuit breaker">fielddata circuit breaker</a>, and is returned
under <code class="literal">fielddata</code> in the <a class="xref" href="cluster-nodes-stats.html" title="Nodes stats API">node stats</a> response.</p>
</div>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="_loading_global_ordinals"></a>Loading global ordinals<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/mapping/params/eager-global-ordinals.asciidoc">edit</a>
</h3>
</div></div></div>
<p>The global ordinal mapping must be built before ordinals can be used during a
search. By default, the mapping is loaded during search on the first time that
global ordinals are needed. This is is the right approach if you are optimizing
for indexing speed, but if search performance is a priority, it’s recommended
to eagerly load global ordinals eagerly on fields that will be used in
aggregations:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT my_index/_mapping
{
  "properties": {
    "tags": {
      "type": "keyword",
      "eager_global_ordinals": true
    }
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/752.console"></div>
<p>When <code class="literal">eager_global_ordinals</code> is enabled, global ordinals are built when a shard
is <a class="xref" href="indices-refresh.html" title="Refresh API">refreshed</a> — Elasticsearch always loads them before
exposing changes to the content of the index. This shifts the cost of building
global ordinals from search to index-time. Elasticsearch will also eagerly
build global ordinals when creating a new copy of a shard, as can occur when
increasing the number of replicas or relocating a shard onto a new node.</p>
<p>Eager loading can be disabled at any time by updating the <code class="literal">eager_global_ordinals</code> setting:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT my_index/_mapping
{
  "properties": {
    "tags": {
      "type": "keyword",
      "eager_global_ordinals": false
    }
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/753.console"></div>
<div class="important admon">
<div class="icon"></div>
<div class="admon_content">
<p>On a <a class="xref" href="frozen-indices.html" title="Frozen indices">frozen index</a>, global ordinals are discarded
after each search and rebuilt again when they’re requested. This means that
<code class="literal">eager_global_ordinals</code> should not be used on frozen indices: it would
cause global ordinals to be reloaded on every search. Instead, the index should
be force-merged to a single segment before being frozen. This avoids building
global ordinals altogether (more details can be found in the next section).</p>
</div>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="_avoiding_global_ordinal_loading"></a>Avoiding global ordinal loading<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/mapping/params/eager-global-ordinals.asciidoc">edit</a>
</h3>
</div></div></div>
<p>Usually, global ordinals do not present a large overhead in terms of their
loading time and memory usage. However, loading global ordinals can be
expensive on indices with large shards, or if the fields contain a large
number of unique term values. Because global ordinals provide a unified mapping
for all segments on the shard, they also need to be rebuilt entirely when a new
segment becomes visible.</p>
<p>In some cases it is possible to avoid global ordinal loading altogether:</p>
<div class="ulist itemizedlist">
<ul class="itemizedlist">
<li class="listitem">
The <code class="literal">terms</code>, <code class="literal">sampler</code>, and <code class="literal">significant_terms</code> aggregations support a
parameter
<a class="xref" href="search-aggregations-bucket-terms-aggregation.html#search-aggregations-bucket-terms-aggregation-execution-hint" title="Execution hint"><code class="literal">execution_hint</code></a>
that helps control how buckets are collected. It defaults to <code class="literal">global_ordinals</code>,
but can be set to <code class="literal">map</code> to instead use the term values directly.
</li>
<li class="listitem">
If a shard has been <a class="xref" href="indices-forcemerge.html" title="Force merge API">force-merged</a> down to a single
segment, then its segment ordinals are already <em>global</em> to the shard. In this
case, Elasticsearch does not need to build a global ordinal mapping and there
is no additional overhead from using global ordinals. Note that for performance
reasons you should only force-merge an index to which you will never write to
again.
</li>
</ul>
</div>
</div>

</div>
<div class="navfooter">
<span class="prev">
<a href="dynamic.html">« <code class="literal">dynamic</code></a>
</span>
<span class="next">
<a href="enabled.html"><code class="literal">enabled</code> »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>